package top.humbleyuan.leet.datastructure.linkedlist;

/**
 * @Author HumbleYuan
 * @Date 2019/9/29 9:05
 * @Des 相交链表
 */
public class IntersectLinkedList {

    private LinkNode firstHead;

    private LinkNode secondHead;

    public IntersectLinkedList(LinkNode firstHead,LinkNode secondHead,int firstIndex,int secondIndex) {
        this.firstHead = firstHead;
        this.secondHead = secondHead;

        LinkNode firstTemp = firstHead;
        LinkNode secondTemp = secondHead;

        for(int i = 0;i < Math.max(firstIndex,secondIndex);i++) {
            firstTemp = i < firstIndex ? firstTemp.next : firstTemp;
            secondTemp = i < secondIndex-1 ? secondTemp.next : secondTemp;
        }

        secondTemp.next = firstTemp;
    }

    public LinkNode getFirstHead() {
        return firstHead;
    }

    public void setFirstHead(LinkNode firstHead) {
        this.firstHead = firstHead;
    }

    public LinkNode getSecondHead() {
        return secondHead;
    }

    public void setSecondHead(LinkNode secondHead) {
        this.secondHead = secondHead;
    }
}
